{extend name="public/basic"}
{block name="main"}
<h1 style = "margin-top:16px;">完善基本信息</h1>
<hr />
<form class = "layui-form ajax _form" method="post" action="{:url('edit_info')}">
    <input type="hidden" name="mer_id" value = "{$mer_id}"/>
    <div class = "layui-row">
        <div class="layui-col-xs8">
            <div class = "layui-form-item">
                <label class = "layui-form-label">商户图标</label>
                <div class = "layui-input-block">
                    <input type="hidden" name="mer_icon" value = "{$info.mer_icon|default=''}" id = "mer_icon"/>
                    <img id = "icon" class = "image-icon "
                         {if condition="isset($info) and !empty($info['mer_icon'])"}
                         src = "{$info.mer_icon|default='/static/images/tianjia.png'}"
                         {else /}
                         src = "/static/images/tianjia.png"
                        {/if}/>
                </div>
            </div>
        </div>
    </div>
    <div class = "layui-row">
        <div class = "layui-col-xs8">
            <div class = "layui-form-item">
                <label class = "layui-form-label">商户名称</label>
                <div class = "layui-input-block">
                    <input type="text" name = "mer_name" value="{$info.mer_name|default=''}" class = "layui-input"/>
                </div>
            </div>
        </div>
    </div>
    <div class = "layui-row">
        <div class = "layui-col-xs8">
            <div class = "layui-form-item">
                <label class = "layui-form-label">店铺地址</label>
                <div class = "layui-input-block">
                    <div class = "layui-col-xs4">
                        <select name = "mer_province" lay-filter="province">
                            <option value = "">请选择省份</option>
                            {volist name="area" id="vo"}
                            <option value = "{$vo.id}" {if condition="isset($info) and $info['mer_province'] eq $vo['id']"}selected{/if}>{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class = "layui-col-xs4">
                        <select name="mer_city" lay-filter="city" id = "city">
                            <option value = "">请选择所在市</option>
                            {if condition="isset($info)"}
                            {:area_option($info['mer_province'],$info['mer_city'])}
                            {/if}
                        </select>
                    </div>
                    <div class = "layui-col-xs4">
                        <select name = "mer_area" id = "area">
                            <option value = "">请选择区</option>
                            {if condition="isset($info)"}
                            {:area_option($info['mer_city'],$info['mer_area'])}
                            {/if}
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class = "layui-row">
        <div class = "layui-col-xs8">
            <div class = "layui-form-item">
                <label class = "layui-form-label">详细地址</label>
                <div class = "layui-input-block">
                    <input type="text" name="mer_address" value = "{$info.mer_address|default=''}" class = "layui-input"/>
                </div>
            </div>
        </div>
    </div>
    <div class = "layui-row">
        <div class = "layui-col-xs8">
            <div class = "layui-form-item">
                <label class = "layui-form-label">联系人</label>
                <div class = "layui-input-block">
                    <input type="text" name="contact_user" value="{$info.contact_user|default=''}" class = "layui-input"/>
                </div>
            </div>
        </div>
    </div>
    <div class = "layui-row">
        <div class = "layui-col-xs8">
            <div class = "layui-form-item">
                <label class = "layui-form-label">联系方式</label>
                <div class = "layui-input-block">
                    <input type="text" name="contact" value="{$info.contact|default=''}" class = "layui-input"/>
                </div>
            </div>
        </div>
    </div>
    <div class = "layui-row">
        <div class = "layui-col-xs8">
            <div class = "layui-form-item">
                <label class = "layui-form-label">简介</label>
                <div class = "layui-input-block">
                    <textarea class = "layui-textarea" name="desc">
                        {$info.desc|default=''}
                    </textarea>
                </div>
            </div>
        </div>
    </div>
    <div class = "layui-row">
        <div class = "layui-col-xs8">
            <button class = "layui-btn layui-btn-success fr">保存</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
    layui.use(["upload","layer","form"],function(){
        var upload = layui.upload;
        var layer = layui.layer;
        var form = layui.form;
        var uploadInst = upload.render({
            elem:"#icon",
            url:"{:url('home/file/upload')}",
            done: function(res) {
                $("#icon").attr("src",res.msg);
                $("#mer_icon").val(res.msg);
            },
            error:function() {
                layer.msg('上传失败');
            }
        })
        form.on("select(province)",function(data){
            var province = data.value;
            console.log(province)
            $.ajax({
                url:"{:url('area/child')}",
                method:"get",
                dataType:"json",
                data:{
                    pid:province
                },
                success:function(res) {
                    if(res.code == 0) {
                        var html = ""
                        html += "<option value = ''>请选择所在市</option>";
                        for(var i = 0;i < res.data.records.length;i++) {
                            html += "<option value = '" + res.data.records[i].id + "'>" + res.data.records[i].name+ "</option>"
                        }
                        $("#city").html(html)
                        form.render("select")
                    }
                }
            });
        })
        form.on("select(city)",function(data){
            var city = data.value;
            $.ajax({
                url:"{:url('area/child')}",
                method:"get",
                dataType:"json",
                data:{
                    pid:city
                },
                success:function(res) {
                    if(res.code == 0) {
                        var html = ""
                        html += "<option value = ''>请选择所在市</option>";
                        for(var i = 0;i < res.data.records.length;i++) {
                            html += "<option value = '" + res.data.records[i].id + "'>" + res.data.records[i].name+ "</option>"
                        }
                        $("#area").html(html)
                        form.render("select")
                    }
                }
            });
        })
    })

{/block}